; 老师的printk是放在head.asm里面的，个人觉得职责不分明，所以单独抽成printk.asm
; 这里最多只支持6个参数
[SECTION .text]
[BITS 64]

extern vsprintf
extern strlen
extern console_write
extern printk_buff
extern console_write_fixed_position

global printk_fixed_position
printk_fixed_position:
    push rdi
    push rsi
    push r9
    push r8
    push rcx
    push rdx

    mov rdi, printk_buff
    mov rdx, rsp
    call vsprintf

    mov rdi, printk_buff
    call strlen
    
    mov rdx, [esp + 8 * 5]
    mov rdi, printk_buff
    mov rsi, rax
    call console_write_fixed_position

    add esp, 8 * 6

    ret

global printk
printk:
    cli
    push rdi
    push r9
    push r8
    push rcx
    push rdx
    push rsi

    mov rsi, rdi
    mov rdi, printk_buff
    mov rdx, rsp
    call vsprintf

    mov rdi, printk_buff
    call strlen

    mov rdi, printk_buff
    mov rsi, rax
    call console_write

    add rsp, 6*8
    sti
    ret